GBML manual / Collision

Slopes

How a collision square can be a ramp instead of a full block - the shapes there are, how a walker climbs and descends them, and the three functions that read and change them.

The idea

A collision square is 8 by 8 pixels. Until now it was all or nothing: the whole square blocked, or none of it did. A shape changes that. A square can block only part of itself, so a row of squares can make a ramp, a hill or a sloped ceiling that a walker climbs instead of bumping into.

Every square still has its class (pass, solid, low cover or one-way) and its flags. A slope or curve drawn in the class One-way is a sloped shelf: you jump up through it from below and walk along its top. The shape only says which pixels of the square count. For a solid or low cover square those are the pixels that block. A pass square blocks nothing, whatever its shape, but its shape still says where its tile flags count (see "Flags on a slope" below). A room you never gave a slope to works exactly as it always did.

You pick a shape for a square in the Room Editor's Collision section, the same way you pick its class. In code you read and change it with tile_shape and tile_set_shape.

The shapes

There is the full square (SHAPE_FULL), and 28 gentle slopes (24 more, steep ones, are described below). Three steepnesses, each in four directions:

The four directions are: a floor rising to the right, a floor rising to the left, a ceiling falling to the right and a ceiling falling to the left. A floor is solid underneath the line, a ceiling is solid above it. In the names, SHAPE_45_FLOOR_UP_RIGHT is a 45 degree floor rising to the right, and SHAPE_22_CEILING_DOWN_LEFT_2 is the second piece of a 22.5 degree ceiling falling to the left.

A square is 8 by 8 pixels: # is solid, . is open.

45 degrees         22.5 degrees                 11.25 degrees
floor rising       floor rising right:          floor rising right:
right: 1 square    low half, high half          pieces 1, 2, 3 and 4

.......#           ........ ......##            ........ ........ ........ ....####
......##           ........ ....####            ........ ........ ........ ########
.....###           ........ ..######            ........ ........ ....#### ########
....####           ........ ########            ........ ........ ######## ########
...#####           ......## ########            ........ ....#### ######## ########
..######           ....#### ########            ........ ######## ######## ########
.#######           ..###### ########            ....#### ######## ######## ########
########           ######## ########            ######## ######## ######## ########
A 45 degree slope, pixel by pixelA 45 degree slope, pixel by pixel
A 45 degree slope, pixel by pixel
A 22.5 degree slope, pixel by pixelA 22.5 degree slope, pixel by pixel
A 22.5 degree slope, pixel by pixel
An 11.25 degree slope, pixel by pixelAn 11.25 degree slope, pixel by pixel
An 11.25 degree slope, pixel by pixel

A slope of several pieces is built by placing the pieces one after the other. Each piece starts as high as the one before it ended, so the ground is one straight line from the first square to the last. The pieces of every slope are numbered from the one with the least solid to the one with the most (piece 1 is the low half of a floor).

The complete list is on the page of each name: SHAPE_FULL, SHAPE_45_FLOOR_UP_RIGHT, SHAPE_45_FLOOR_UP_LEFT, SHAPE_45_CEILING_DOWN_RIGHT, SHAPE_45_CEILING_DOWN_LEFT, and the 22 and 11 degree ones beside them. Shapes you draw yourself in the Room Editor ("Draw your own") get a number from 128 up, in the order you made them.

Painting slopes in the Room Editor

Open the Collision section, turn on Attribute brush, pick Solid (or Low cover), and look at the small Shape section under the Pass / Solid / Low cover / Keep buttons. It is a row of icon buttons:

Pick a slope and more rows appear. Rotate 90° turns the picked shape a quarter turn (the T key does the same) and Mirror image turns it round, left to right (Shift+T). Between them they give a floor rising to the right or to the left and a ceiling falling to the right or to the left, and rotating a 22.5° or 11.25° slope gives a steep one (see "Steep slopes" below); four quarter turns bring you back. A shape you drew yourself cannot be rotated here, so both buttons are grayed for it (its Edit shape window has Flip left-right and Flip up-down). A slope made of several pieces also shows its Pieces, in the order they are placed (a steep slope's one above the other), and the piece you pick is the one a click paints.

Draw slope draws a whole slope in one drag. Press it and a small popup asks which collision to draw: one class, Pass, Solid or Low cover, and, if you want, any of your own tile flags as tickboxes (none, one or several). Both choices are remembered for next time. Then press on the room and drag a line, like the Line tool in the Paint tab. While you drag, the line snaps to the nearest angle (11.25, 22.5, 45, 67.5 or 78.75 degrees) and shows the squares it will make; let go and every square along the line gets the right piece, and when a run of pieces ends the slope climbs one row, so a long slope stays one straight line. A line steeper than 45 degrees snaps to a steep slope (see "Steep slopes" below): each column across is a stack of two squares (67.5 degrees) or four (78.75 degrees), and the next column's stack starts where the last one ends, so the slope is a staircase of steep faces. Solid below (the default) makes a floor you walk on, Solid above makes a ceiling. One Undo takes back the whole slope, and a right-click or Escape puts a drag down. With the pencil a click or a drag paints only the piece you picked.

The Tile Palette has the same Draw slope while an autotile that includes slopes is picked (tick Include slopes for it in the Paint tab; tick Steep slope pieces too and a line steeper than 45 degrees is drawn with the steep ones). It draws the autotile's own slope pieces along the line (and its slope edge pieces under and beside the ramp, when it has them), joins the ends to the ground and gives every square the class and the flags you chose. With Closed shape ticked it also fills the solid side with the autotile's ordinary pieces.

Dragging to the right across four squares with a 22.5 degree floor rising to the right.
The two squares on the lower left are the ones you press on and drag over: piece 1, then piece 2. The ramp then climbs a row: the two squares on the upper right are piece 1 and piece 2 again.

........ ........ ........ ......##
........ ........ ........ ....####
........ ........ ........ ..######
........ ........ ........ ########
........ ........ ......## ########
........ ........ ....#### ########
........ ........ ..###### ########
........ ........ ######## ########
........ ......## ........ ........
........ ....#### ........ ........
........ ..###### ........ ........
........ ######## ........ ........
......## ######## ........ ........
....#### ######## ........ ........
..###### ######## ........ ........
######## ######## ........ ........

Fill and Rect paint the piece you picked in every square. Pass paints the shape too, like Solid and Low cover (a pass square with a shape blocks nothing, but its flags follow the shape). Erasing gives the full square back, and Keep leaves the shapes as they are. With Show collision overlay on, a square with a shape is tinted only where it is solid. Draw your own: click or drag to make pixels solid, press on a solid pixel and drag to clear, give the shape a name and press Save shape; right-click its button to edit, rename or delete it (a shape a room uses cannot be deleted until its squares are painted over). The first shape you draw is number 128, the next 129, and so on, which is the number tile_set_shape takes.

What a slope does to things that move

Everything that asks the room whether a place is free asks about the pixels, not the whole square:

Steep slopes

Turn a 22.5 degree slope a quarter turn and it is a 67.5 degree slope: one square wide and two tall. Turn an 11.25 degree one and it is a 78.75 degree slope, one square wide and four tall. They come in the same four directions (a floor rising to the right or left, a ceiling falling to the right or left), with the piece with the least solid first, and are the shapes numbered 29 to 52 (29 to 36 are the 67.5 degree ones, 37 to 52 the 78.75 degree ones). A game that does not use them is exactly what it was. In code they are SHAPE_67_FLOOR_UP_RIGHT_1 to _2 and SHAPE_78_FLOOR_UP_RIGHT_1 to _4, and the same names for the other three directions (SHAPE_67_CEILING_DOWN_LEFT_2 is the second piece of a 67.5 degree ceiling falling to the left). Piece 1 has the least solid; the pieces of a steep slope stand one above the other, and for a floor piece 1 is the top one. Draw Curve uses them where the curve is steeper than 45 degrees.

A slope steeper than 45 degrees cannot be walked up. It is a wall with a slanted face:

Joins that are smooth. A steep stack has a foot (its bottom corner) and a top (its top corner). At the foot it meets a flat floor, the high end of a 45, 22.5 or 11.25 degree ramp that rises up to it (the surface goes on up, steeper: the foot of a dome), or the next steep stack down. At the top it meets the flat plateau, the low end of a gentle ramp that rises on from it (the surface goes on up, flatter: the shoulder of a dome), or the next steep stack up. A walker that walks off a shoulder onto the face slides down it; one that lands on the foot ramp walks on along it; one that walks up the foot ramp stops at the face. Draw Curve and Draw slope make only these joins, so a tall dome goes smoothly from flat to 11.25 to 22.5 to 45 to 67.5 to 78.75 degrees and back, with no flat ledge halfway up. Never a V (a gentle ramp falling toward the foot of a stack, so the ground turns up into it) and never a crest (a ramp falling away from its top, a peak): a walker could hang on the corner there.

Edge pieces beside a steep slope. An autotile that has both slope edge pieces and steep slope pieces can have edge pieces beside its steep slopes too, so the grassy band follows the steep face the way it follows a gentle ramp: a piece beside each square of the steep face (on the side the ground is), a crest piece on the flat top square beside the top of the face, and a foot piece on the ground square at its lower end. Gbabel lays them wherever it lays the steep slope, and lays the ordinary piece for any of them you have not drawn.

Flags on a slope: poison grass

A tile flag is a mark of your own on a square (hurtful, water, poison; see tile flags). On a square with a shape, the flag counts only on the solid part of the shape. tile_flags asked about a point in the empty part of the square answers as if the square had no flags.

Take a slope of poison grass that the player walks through: a 45 degree slope whose squares are Pass and carry a flag you named poison. The grass is the solid part of each square, the triangle under the slope's line. The air above the line is the empty part.

var in_grass = (tile_flags(x, y + 8) & FLAG_POISON) != 0;

Reads the flags a little below the walker's middle and records whether the flag called poison is set there. When the walker's feet are down in the grass the answer has the poison bit. When it walks through the air above the grass, in the very same squares, the answer does not. Without the shape the whole square would be poison, and the walker would be hurt in the air above the grass too.

What this follows from:

Standing on a slope: the feet

A walker is a box, and a box is wide. A 16 pixel wide box standing on a 45 degree ramp would, if the whole width had to be above the ground, rest on the highest ground under it, up to 8 pixels above the line, and look like it floats. So a body that touches a slope stands on its feet: the one pixel column at the bottom middle of its box.

A body standing on a ramp: its feet on the lineA body standing on a ramp: its feet on the line
A body standing on a ramp: its feet on the line
A 16 by 16 body on a 45 degree ramp (# ramp, B body, F the feet).
The body sinks into the ramp beside its feet; only the feet touch the line.

              BBBBBBBBBBBBBBBB    ######
              BBBBBBBBBBBBBBBB   #######
              BBBBBBBBBBBBBBBB  ########
              BBBBBBBBBBBBBBBB #########
              BBBBBBBBBBBBBBBB##########
              BBBBBBBBBBBBBBBB##########
              BBBBBBBBBBBBBBBB##########
              BBBBBBBBBBBBBBBB##########
              BBBBBBBBBBBBBBBB##########
              BBBBBBBBBBBBBBBB##########
              BBBBBBBBBBBBBBBB##########
              BBBBBBBBFBBBBBBB##########
                      ##################
                     ###################

Games that have no ground (a top-down game) do not want this. slope_feet switches it off for the whole game, and a body is then a whole box that slides along any slope or diagonal wall it is pushed into, in any direction. The Player movement tab turns it off by itself for a game whose designs are all top-down, grid, ship or spin.

Code that moves with tile_free one direction at a time can use the same idea by hand: when the step sideways is blocked, try the same step with the walker lifted by up to the same number of pixels, and use tile_ground_y to put it down on the ground again after a step down.

var step = hsp;
if (tile_free(x + step, y)) {
    x += step;
} else if (tile_free(x + step, y - 1)) {
    x += step;
    y -= 1;
}

Walks one pixel up the 45 degree ramp that is in the way. A 22.5 degree ramp needs the lift only every other pixel, and a loop over the lift sizes 1 to 8 handles every slope the same way.

Things to know

See also: tile_shapetile_set_shapetile_ground_ytile_freetile_walltile_solidmove_slideOverlap and collisionCollision layersSHAPE_FULL